// $Id: NewAttributeForm.cs 64 2008-05-06 18:29:47Z nvivo $

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DBLGen.UI.Design
{
    public partial class NewAttributeForm : Form
    {
        private string _newName;
        private CustomAttributes _currentAttributes;

        public NewAttributeForm(CustomAttributes ca)
        {
            if (ca == null)
                throw new ArgumentNullException("ca");

            InitializeComponent();

            _currentAttributes = ca;
        }

        public string NewName
        {
            get
            {
                return _newName;
            }
            private set
            {
                _newName = value;
            }
        }

        public CustomAttributes CurrentAttributes
        {
            get
            {
                return _currentAttributes;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();

            if (String.IsNullOrEmpty(name))
            {
                MessageBox.Show("The name can't be empty.");
                txtName.Select();
            }
            else if (CurrentAttributes.ContainsKey(name))
            {
                MessageBox.Show("This attribute already exists.");
                txtName.Select();
            }
            else
            {
                DialogResult = DialogResult.OK;
                NewName = name;
                Close();
            }
        }

        private void NewAttributeForm_Load(object sender, EventArgs e)
        {
            if (CurrentAttributes == null)
                throw new InvalidOperationException("CurrentAttributes must be set prior to Load.");

            txtName.Select();
        }
    }
}